package com.ruoyi.project.module.fbsDetail.controller;

import java.util.List;

import com.ruoyi.common.constant.ErpEnums;
import com.ruoyi.common.utils.UserUtils;
import com.ruoyi.project.module.purchases.domain.Purchases;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.constant.BusinessType;
import com.ruoyi.project.module.fbsDetail.domain.FbsDetail;
import com.ruoyi.project.module.fbsDetail.service.IFbsDetailService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * FBS明细 信息操作处理
 * 
 * @author lcx
 * @date 2018-09-17
 */
@Controller
@RequestMapping("/module/fbsDetail")
public class FbsDetailController extends BaseController
{
    private String prefix = "module/fbsDetail";
	
	@Autowired
	private IFbsDetailService fbsDetailService;
	
	@RequiresPermissions("module:fbsDetail:view")
	@GetMapping()
	public String fbsDetail()
	{
	    return prefix + "/fbsDetail";
	}
	
	/**
	 * 查询FBS明细列表
	 */
	@RequiresPermissions("module:fbsDetail:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(FbsDetail fbsDetail)
	{
		startPageChange();
		fbsDetail.setCompanyId(UserUtils.getDepId());
        List<FbsDetail> list = fbsDetailService.selectFbsDetailList(fbsDetail);

        //合计
		List<FbsDetail> sumCountList = fbsDetailService.selectSumCountFbsDetailList(fbsDetail);

		return getDataTableAsSum(list, sumCountList);
	}
	
	/**
	 * 新增FBS明细
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存FBS明细
	 */
	@RequiresPermissions("module:fbsDetail:add")
	@Log(title = "FBS明细", action = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(FbsDetail fbsDetail)
	{		
		return toAjax(fbsDetailService.insertFbsDetail(fbsDetail));
	}

	/**
	 * 修改FBS明细
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		FbsDetail fbsDetail = fbsDetailService.selectFbsDetailById(id);
		mmap.put("fbsDetail", fbsDetail);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存FBS明细
	 */
	@RequiresPermissions("module:fbsDetail:edit")
	@Log(title = "FBS明细", action = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(FbsDetail fbsDetail)
	{		
		return toAjax(fbsDetailService.updateFbsDetail(fbsDetail));
	}
	
	/**
	 * 删除FBS明细
	 */
	@RequiresPermissions("module:fbsDetail:remove")
	@Log(title = "FBS明细", action = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(fbsDetailService.deleteFbsDetailByIds(ids));
	}
	
}
